/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.ssm.changeunit.communicate;


import com.ssm.changeunit.ChangeUnitException;
import com.ssm.changeunit.persistance.*;
import com.ssm.changeunit.util.ChangeUnitTraveler;
import java.util.List;
import java.util.ArrayList;


/**
 *
 * @author EuiHyun
 */
public class DBToXML {

   /* 
    public String getXmlUsers(){

       String xml_data="";
	//USERID VARCHAR(100) not null primary key,
	//USERPASSWORD VARCHAR(100),
	//USEREMAIL VARCHAR(500)

        return xml_data;
    }
    */

    
    private List<String> getAfterChangeUnitId(String changeUnitId) throws ChangeUnitException {
        
        List<String> changeUnitIdList = new ArrayList<String>();

        
        ChangeUnitTraveler changeUnitTraveler = new ChangeUnitTraveler(ChangeUnitTraveler.Direct.Child, changeUnitId, null);
        changeUnitTraveler.init();
        
        int i = 0;
        while(changeUnitTraveler.hasNext()){
            if(i!=0){
                changeUnitIdList.add(changeUnitTraveler.getNextChangeUnit().getChangeUnitId());
            }
            i++;
        }
        
        return changeUnitIdList;
    }
    
    public String getXmlManagedChangeUnit() throws ChangeUnitException {

       String xml_data="";
/*
    MANAGEDCHANGEUNITID VARCHAR(100) not null primary key
*/
         xml_data+="<MANAGEDCHANGEUNIT>";
         ManagedChangeUnitDAO managedChangeUnitDAO = new ManagedChangeUnitDAO();

         try{
            ManagedChangeUnitDTO dto = managedChangeUnitDAO.find();

           xml_data+="<ROW>";

           xml_data+="<MANAGEDCHANGEUNITID>";
           xml_data+=dto.getManagedChangeUnitId();
           xml_data+="</MANAGEDCHANGEUNITID>";

           xml_data+="</ROW>";

         }
         catch(PersistanceException ex) {
             throw new ChangeUnitException(ex);
         }
         xml_data+="</MANAGEDCHANGEUNIT>";       
      
         
        return xml_data;
    }


    public String getXmlTag() throws ChangeUnitException {

       String xml_data="";
/*
	TAGNAME VARCHAR(100) not null primary key,
	CHANGEUNITID VARCHAR(100) not null
*/
         xml_data+="<TAG>";
         TagDAO tagDAO = new TagDAO();

         try{
            List<TagDTO> list = tagDAO.list();

            for(TagDTO dto : list){
               xml_data+="<ROW>";
               xml_data+="<TAGNAME>";
               xml_data+=dto.getTagName();
               xml_data+="</TAGNAME>";
               xml_data+="<CHANGEUNITID>";
               xml_data+=dto.getChangeUnitId();
               xml_data+="</CHANGEUNITID>";
               xml_data+="</ROW>";
            }
         }
         catch(PersistanceException ex) {
             throw new ChangeUnitException(ex);
         }
         xml_data+="</TAG>";

 
        return xml_data;
    }   
    
    public String getXmlTag(String changeUnitId) throws ChangeUnitException {

       String xml_data="";
/*
	TAGNAME VARCHAR(100) not null primary key,
	CHANGEUNITID VARCHAR(100) not null
*/
         xml_data+="<TAG>";
         TagDAO tagDAO = new TagDAO();

         try{
            
            List<String> changeUnitIds = getAfterChangeUnitId(changeUnitId);
            
            for(String item :changeUnitIds){
 
                List<TagDTO> list = tagDAO.findByChangeUnitId(item);
                for(TagDTO dto : list){
                   xml_data+="<ROW>";
                   xml_data+="<TAGNAME>";
                   xml_data+=dto.getTagName();
                   xml_data+="</TAGNAME>";
                   xml_data+="<CHANGEUNITID>";
                   xml_data+=dto.getChangeUnitId();
                   xml_data+="</CHANGEUNITID>";
                   xml_data+="</ROW>";
                }
            }
         }
         catch(PersistanceException ex) {
             throw new ChangeUnitException(ex);
         }
         xml_data+="</TAG>";

        return xml_data;
    }      
    
    public String getXmlProject() throws ChangeUnitException {

       String xml_data="";
/*
	PROJECTID VARCHAR(100) not null primary key
*/
         xml_data+="<PROJECT>";
         ProjectDAO projectDAO = new ProjectDAO();

         try{
            ProjectDTO dto = projectDAO.find();

           xml_data+="<ROW>";
           xml_data+="<PROJECTID>";

           xml_data+=dto.getProjectId();

           xml_data+="</PROJECTID>";
           xml_data+="</ROW>";

         }
         catch(PersistanceException ex) {
             throw new ChangeUnitException(ex);
         }
         xml_data+="</PROJECT>";

        return xml_data;
    }

    public String getXmlParent() throws ChangeUnitException {

       String xml_data="";
/*
	PARENTID VARCHAR(100) not null primary key,
	CHANGEUNITID VARCHAR(100) not null,
	PARENTCHANGEUNITID VARCHAR(100) not null
*/
         xml_data+="<PARENT>";
         ParentDAO parentDAO = new ParentDAO();

         try{
            List<ParentDTO> list = parentDAO.list();

            for(ParentDTO dto : list){
               xml_data+="<ROW>";
               
               xml_data+="<PARENTID>";
               xml_data+=dto.getParentId();
               xml_data+="</PARENTID>";
               xml_data+="<CHANGEUNITID>";
               xml_data+=dto.getChangeUnitId();
               xml_data+="</CHANGEUNITID>";
               xml_data+="<PARENTCHANGEUNITID>";
               xml_data+=dto.getParentChangeUnitId();
               xml_data+="</PARENTCHANGEUNITID>";
               
               xml_data+="</ROW>";
            }
         }
         catch(PersistanceException ex) {
             throw new ChangeUnitException(ex);
         }
         xml_data+="</PARENT>";
             
        return xml_data;
    }

    public String getXmlParent(String changeUnitId) throws ChangeUnitException {

       String xml_data="";
/*
	PARENTID VARCHAR(100) not null primary key,
	CHANGEUNITID VARCHAR(100) not null,
	PARENTCHANGEUNITID VARCHAR(100) not null
*/
         xml_data+="<PARENT>";
         ParentDAO parentDAO = new ParentDAO();

         try{
             
            List<String> changeUnitIds = getAfterChangeUnitId(changeUnitId);
            
            for(String item :changeUnitIds){
            List<ParentDTO> list = parentDAO.findByChangeUnitId(item);

                for(ParentDTO dto : list){
                   xml_data+="<ROW>";

                   xml_data+="<PARENTID>";
                   xml_data+=dto.getParentId();
                   xml_data+="</PARENTID>";
                   xml_data+="<CHANGEUNITID>";
                   xml_data+=dto.getChangeUnitId();
                   xml_data+="</CHANGEUNITID>";
                   xml_data+="<PARENTCHANGEUNITID>";
                   xml_data+=dto.getParentChangeUnitId();
                   xml_data+="</PARENTCHANGEUNITID>";

                   xml_data+="</ROW>";
                }
            }
         }
         catch(PersistanceException ex) {
             throw new ChangeUnitException(ex);
         }
         xml_data+="</PARENT>";
             
        return xml_data;
    }
    
    public String getXmlMangeItemList() throws ChangeUnitException {

       String xml_data="";
/*
	FILEPATH VARCHAR(255) not null primary key
*/
         xml_data+="<MANAGEDITEMLIST>";
         ManagedItemListDAO managedItemListDAO = new ManagedItemListDAO();

         try{
            List<ManagedItemListDTO> list = managedItemListDAO.list();

            for(ManagedItemListDTO dto : list){
               xml_data+="<ROW>";
               
               xml_data+="<FILEPATH>";
               xml_data+=dto.getFilePath();
               xml_data+="</FILEPATH>";
               
               xml_data+="</ROW>";
            }
         }
         catch(PersistanceException ex) {
             throw new ChangeUnitException(ex);
         }
         xml_data+="</MANAGEDITEMLIST>";            
         
        return xml_data;
    }


    public String getXmlChild() throws ChangeUnitException {

       String xml_data="";
/*
	CHILDID VARCHAR(100) not null primary key,
	CHANGEUNITID VARCHAR(100) not null,
	CHILDCHANGEUNITID VARCHAR(100) not null
*/
         xml_data+="<CHILD>";
         ChildDAO childDAO = new ChildDAO();

         try{
            List<ChildDTO> list = childDAO.list();

            for(ChildDTO dto : list){
               xml_data+="<ROW>";
               
               xml_data+="<CHILDID>";
               xml_data+=dto.getChildId();
               xml_data+="</CHILDID>";
               xml_data+="<CHANGEUNITID>";
               xml_data+=dto.getChangeUnitId();
               xml_data+="</CHANGEUNITID>";
               xml_data+="<CHILDCHANGEUNITID>";
               xml_data+=dto.getChildChangeUnitId();
               xml_data+="</CHILDCHANGEUNITID>";
               
               xml_data+="</ROW>";
            }
         }
         catch(PersistanceException ex) {
             throw new ChangeUnitException(ex);
         }
         xml_data+="</CHILD>";              
         
        return xml_data;
    }

    public String getXmlChild(String changeUnitId) throws ChangeUnitException {

       String xml_data="";
/*
	CHILDID VARCHAR(100) not null primary key,
	CHANGEUNITID VARCHAR(100) not null,
	CHILDCHANGEUNITID VARCHAR(100) not null
*/
         xml_data+="<CHILD>";
         ChildDAO childDAO = new ChildDAO();

         try{ 
            List<String> changeUnitIds = getAfterChangeUnitId(changeUnitId);
            
            for(String item :changeUnitIds){
                
                List<ChildDTO> list = childDAO.findByChangeUnitId(item);

                for(ChildDTO dto : list){
                   xml_data+="<ROW>";

                   xml_data+="<CHILDID>";
                   xml_data+=dto.getChildId();
                   xml_data+="</CHILDID>";
                   xml_data+="<CHANGEUNITID>";
                   xml_data+=dto.getChangeUnitId();
                   xml_data+="</CHANGEUNITID>";
                   xml_data+="<CHILDCHANGEUNITID>";
                   xml_data+=dto.getChildChangeUnitId();
                   xml_data+="</CHILDCHANGEUNITID>";

                   xml_data+="</ROW>";
                }
            }
         }
         catch(PersistanceException ex) {
             throw new ChangeUnitException(ex);
         }
         xml_data+="</CHILD>";              
         
        return xml_data;
    }    
    
    public String getXmlChangeUnitItem() throws ChangeUnitException {

       String xml_data="";
/*
	CHANGEUNITITEMID VARCHAR(100) not null primary key,

        CHANGEUNITID VARCHAR(100),
	FILEPATH VARCHAR(255),
	FIRSTPARENTCHANGEUNITID VARCHAR(100),
	FIRSTPARENTCHANGEUNITITEMID VARCHAR(100),
	SECONDPARENTCHANGEUNITID VARCHAR(100),
	SECONDPARENTCHANGEUNITITEMID VARCHAR(100),

        REFCHANGELOGID VARCHAR(100)
*/
         xml_data+="<CHANGEUNITITEM>";
         ChangeUnitItemDAO changeUnitItemDAO = new ChangeUnitItemDAO();

         try{
            List<ChangeUnitItemDTO> list = changeUnitItemDAO.list();

            for(ChangeUnitItemDTO dto : list){
               xml_data+="<ROW>";
               
               xml_data+="<CHANGEUNITITEMID>";
               xml_data+=dto.getChangeUnitItemId();
               xml_data+="</CHANGEUNITITEMID>";
               xml_data+="<CHANGEUNITID>";
               xml_data+=dto.getChangeUnitId();
               xml_data+="</CHANGEUNITID>";
               xml_data+="<FILEPATH>";
               xml_data+=dto.getFilePath();
               xml_data+="</FILEPATH>";
               xml_data+="<FIRSTPARENTCHANGEUNITID>";
               xml_data+=dto.getFirstParentChangeUnitId();
               xml_data+="</FIRSTPARENTCHANGEUNITID>";
               xml_data+="<FIRSTPARENTCHANGEUNITITEMID>";
               xml_data+=dto.getFirstParentChangeUnitItemId();
               xml_data+="</FIRSTPARENTCHANGEUNITITEMID>";
               xml_data+="<SECONDPARENTCHANGEUNITID>";
               xml_data+=dto.getSecondParentChangeUnitId();
               xml_data+="</SECONDPARENTCHANGEUNITID>";
               xml_data+="<SECONDPARENTCHANGEUNITITEMID>";
               xml_data+=dto.getSecondParentChangeUnitItemId();
               xml_data+="</SECONDPARENTCHANGEUNITITEMID>";
               xml_data+="<REFCHANGELOGID>";
               xml_data+=dto.getRefChangeLogId();
               xml_data+="</REFCHANGELOGID>";
               
               xml_data+="</ROW>";
            }
         }
         catch(PersistanceException ex) {
             throw new ChangeUnitException(ex);
         }
         xml_data+="</CHANGEUNITITEM>";                  
         
        return xml_data;
    }

    public String getXmlChangeUnitItem(String changeUnitId) throws ChangeUnitException {

       String xml_data="";
/*
	CHANGEUNITITEMID VARCHAR(100) not null primary key,

        CHANGEUNITID VARCHAR(100),
	FILEPATH VARCHAR(255),
	FIRSTPARENTCHANGEUNITID VARCHAR(100),
	FIRSTPARENTCHANGEUNITITEMID VARCHAR(100),
	SECONDPARENTCHANGEUNITID VARCHAR(100),
	SECONDPARENTCHANGEUNITITEMID VARCHAR(100),

        REFCHANGELOGID VARCHAR(100)
*/
         xml_data+="<CHANGEUNITITEM>";
         ChangeUnitItemDAO changeUnitItemDAO = new ChangeUnitItemDAO();

         try{
            List<String> changeUnitIds = getAfterChangeUnitId(changeUnitId);
            
            for(String item :changeUnitIds){
                List<ChangeUnitItemDTO> list = changeUnitItemDAO.findByChangeUnitId(item);

                for(ChangeUnitItemDTO dto : list){
                   xml_data+="<ROW>";

                   xml_data+="<CHANGEUNITITEMID>";
                   xml_data+=dto.getChangeUnitItemId();
                   xml_data+="</CHANGEUNITITEMID>";
                   xml_data+="<CHANGEUNITID>";
                   xml_data+=dto.getChangeUnitId();
                   xml_data+="</CHANGEUNITID>";
                   xml_data+="<FILEPATH>";
                   xml_data+=dto.getFilePath();
                   xml_data+="</FILEPATH>";
                   xml_data+="<FIRSTPARENTCHANGEUNITID>";
                   xml_data+=dto.getFirstParentChangeUnitId();
                   xml_data+="</FIRSTPARENTCHANGEUNITID>";
                   xml_data+="<FIRSTPARENTCHANGEUNITITEMID>";
                   xml_data+=dto.getFirstParentChangeUnitItemId();
                   xml_data+="</FIRSTPARENTCHANGEUNITITEMID>";
                   xml_data+="<SECONDPARENTCHANGEUNITID>";
                   xml_data+=dto.getSecondParentChangeUnitId();
                   xml_data+="</SECONDPARENTCHANGEUNITID>";
                   xml_data+="<SECONDPARENTCHANGEUNITITEMID>";
                   xml_data+=dto.getSecondParentChangeUnitItemId();
                   xml_data+="</SECONDPARENTCHANGEUNITITEMID>";
                   xml_data+="<REFCHANGELOGID>";
                   xml_data+=dto.getRefChangeLogId();
                   xml_data+="</REFCHANGELOGID>";

                   xml_data+="</ROW>";
                }
            }
         }
         catch(PersistanceException ex) {
             throw new ChangeUnitException(ex);
         }
         xml_data+="</CHANGEUNITITEM>";                  
         
        return xml_data;
    }
    
    public String getXmlChangeUnitBranch() throws ChangeUnitException {

       String xml_data="";
/*
	CHANGEUNITID VARCHAR(100) not null,
	BRANCHNAME VARCHAR(100) not null
*/
         xml_data+="<CHANGEUNITBRANCH>";
         ChangeUnitBranchDAO changeUnitBranchDAO = new ChangeUnitBranchDAO();

         try{
            List<ChangeUnitBranchDTO> list = changeUnitBranchDAO.list();

            for(ChangeUnitBranchDTO dto : list){
               xml_data+="<ROW>";
               
               xml_data+="<CHANGEUNITID>";
               xml_data+=dto.getChangeUnitId();
               xml_data+="</CHANGEUNITID>";
               xml_data+="<BRANCHNAME>";
               xml_data+=dto.getBranchName();
               xml_data+="</BRANCHNAME>";
               
               xml_data+="</ROW>";
            }
         }
         catch(PersistanceException ex) {
             throw new ChangeUnitException(ex);
         }
         xml_data+="</CHANGEUNITBRANCH>";              
         
        return xml_data;
    }

    public String getXmlChangeUnitBranch(String changeUnitId) throws ChangeUnitException {

       String xml_data="";
/*
	CHANGEUNITID VARCHAR(100) not null,
	BRANCHNAME VARCHAR(100) not null
*/
         xml_data+="<CHANGEUNITBRANCH>";
         ChangeUnitBranchDAO changeUnitBranchDAO = new ChangeUnitBranchDAO();

         try{
            List<String> changeUnitIds = getAfterChangeUnitId(changeUnitId);
            
            for(String item :changeUnitIds){
                List<ChangeUnitBranchDTO> list = changeUnitBranchDAO.findByChangeUnitId(item);

                for(ChangeUnitBranchDTO dto : list){
                   xml_data+="<ROW>";

                   xml_data+="<CHANGEUNITID>";
                   xml_data+=dto.getChangeUnitId();
                   xml_data+="</CHANGEUNITID>";
                   xml_data+="<BRANCHNAME>";
                   xml_data+=dto.getBranchName();
                   xml_data+="</BRANCHNAME>";

                   xml_data+="</ROW>";
                }
            }
         }
         catch(PersistanceException ex) {
             throw new ChangeUnitException(ex);
         }
         xml_data+="</CHANGEUNITBRANCH>";              
         
        return xml_data;
    }
    
    public String getXmlChangeUnit() throws ChangeUnitException {

       String xml_data="";
/*
	CHANGEUNITID VARCHAR(100) not null primary key,
	LOG VARCHAR(255),
	DATE DATE not null,
	TIME TIME not null,
	USERID VARCHAR(100) not null
*/
         xml_data+="<CHANGEUNIT>";
         ChangeUnitDAO changeUnitDAO = new ChangeUnitDAO();

         try{
            List<ChangeUnitDTO> list = changeUnitDAO.list();

            for(ChangeUnitDTO dto : list){
               xml_data+="<ROW>";
               
               xml_data+="<CHANGEUNITID>";
               xml_data+=dto.getChangeUnitId();
               xml_data+="</CHANGEUNITID>";
               xml_data+="<LOG>";
               xml_data+=dto.getLog();
               xml_data+="</LOG>";
               xml_data+="<DATE>";
               xml_data+=dto.getDate().toString();
               xml_data+="</DATE>";
               xml_data+="<TIME>";
               xml_data+=dto.getTime().toString();
               xml_data+="</TIME>";
               
               xml_data+="<USERID>";
               xml_data+=dto.getUserId();
               xml_data+="</USERID>";
               
               xml_data+="</ROW>";
            }
         }
         catch(PersistanceException ex) {
             throw new ChangeUnitException(ex);
         }
         xml_data+="</CHANGEUNIT>";                     
         
        return xml_data;
    }

    public String getXmlChangeUnit(String changeUnitId) throws ChangeUnitException {

       String xml_data="";
/*
	CHANGEUNITID VARCHAR(100) not null primary key,
	LOG VARCHAR(255),
	DATE DATE not null,
	TIME TIME not null,
	USERID VARCHAR(100) not null
*/
         xml_data+="<CHANGEUNIT>";
         ChangeUnitDAO changeUnitDAO = new ChangeUnitDAO();

         try{
            List<String> changeUnitIds = getAfterChangeUnitId(changeUnitId);
            
            for(String item :changeUnitIds){
               ChangeUnitDTO dto = changeUnitDAO.find(item);

               xml_data+="<ROW>";

               xml_data+="<CHANGEUNITID>";
               xml_data+=dto.getChangeUnitId();
               xml_data+="</CHANGEUNITID>";
               xml_data+="<LOG>";
               xml_data+=dto.getLog();
               xml_data+="</LOG>";
               xml_data+="<DATE>";
               xml_data+=dto.getDate().toString();
               xml_data+="</DATE>";
               xml_data+="<TIME>";
               xml_data+=dto.getTime().toString();
               xml_data+="</TIME>";
               xml_data+="<USERID>";
               xml_data+=dto.getUserId();
               xml_data+="</USERID>";

               xml_data+="</ROW>";
                
            }
         }
         catch(PersistanceException ex) {
             throw new ChangeUnitException(ex);
         }
         xml_data+="</CHANGEUNIT>";                     
         
        return xml_data;
    }
    
    public String getXmlChangeLog() throws ChangeUnitException {

       String xml_data="";
/*
	CHANGELOGID VARCHAR(100) not null primary key,
	FILEPATH VARCHAR(255),
	CONTENT BLOB(2147483647)
*/
         xml_data+="<CHANGELOG>";
         ChangeLogDAO changeLogDAO = new ChangeLogDAO();

         try{
            List<ChangeLogDTO> list = changeLogDAO.list();

            for(ChangeLogDTO dto : list){
               xml_data+="<ROW>";
               
               xml_data+="<CHANGELOGID>";
               xml_data+=dto.getChangeLogId();
               xml_data+="</CHANGELOGID>";
               xml_data+="<FILEPATH>";
               xml_data+=dto.getFilePath();
               xml_data+="</FILEPATH>";
               xml_data+="<CONTENT>";
               xml_data+=new String(dto.getContent());
               xml_data+="</CONTENT>";
               
               xml_data+="</ROW>";
            }
         }
         catch(PersistanceException ex) {
             throw new ChangeUnitException(ex);
         }
         xml_data+="</CHANGELOG>";              
         
        return xml_data;             
         
    }

    public String getXmlChangeLog(String changeUnitId) throws ChangeUnitException {

       String xml_data="";
/*
	CHANGELOGID VARCHAR(100) not null primary key,
	FILEPATH VARCHAR(255),
	CONTENT BLOB(2147483647)
*/
         xml_data+="<CHANGELOG>";
         ChangeLogDAO changeLogDAO = new ChangeLogDAO();

         try{
            List<String> changeUnitIds = getAfterChangeUnitId(changeUnitId);
            
            for(String item :changeUnitIds){
                
                ChangeUnitItemDAO changeUnitItemDAO = new ChangeUnitItemDAO();
                List<ChangeUnitItemDTO> dtolist = changeUnitItemDAO.findByChangeUnitId(item);
                
                for(ChangeUnitItemDTO item2 : dtolist){
                    
                   ChangeLogDTO dto = changeLogDAO.find(item2.getChangeUnitItemId());

                   xml_data+="<ROW>";

                   xml_data+="<CHANGELOGID>";
                   xml_data+=dto.getChangeLogId();
                   xml_data+="</CHANGELOGID>";
                   xml_data+="<FILEPATH>";
                   xml_data+=dto.getFilePath();
                   xml_data+="</FILEPATH>";
                   xml_data+="<CONTENT>";
                   xml_data+=new String(dto.getContent());
                   xml_data+="</CONTENT>";

                   xml_data+="</ROW>";
                }
            }
         }
         catch(PersistanceException ex) {
             throw new ChangeUnitException(ex);
         }
         xml_data+="</CHANGELOG>";              
         
        return xml_data;             
         
    }
    
    public String getXmlBranch() throws ChangeUnitException {

       String xml_data="";
/*
	BRANCHNAME VARCHAR(100) not null primary key,
	CHANGEUNITID VARCHAR(100) not null,
	ORIGINCHANGEUNITID VARCHAR(100) not null
*/
         xml_data+="<BRANCH>";
         BranchDAO branchDAO = new BranchDAO();

         try{
            List<BranchDTO> list = branchDAO.list();

            for(BranchDTO dto : list){
               xml_data+="<ROW>";
               
               xml_data+="<BRANCHNAME>";
               xml_data+=dto.getBranchName();
               xml_data+="</BRANCHNAME>";
               xml_data+="<CHANGEUNITID>";
               xml_data+=dto.getChangeUnitId();
               xml_data+="</CHANGEUNITID>";
               xml_data+="<ORIGINCHANGEUNITID>";
               xml_data+=dto.getOriginChangeUnitId();
               xml_data+="</ORIGINCHANGEUNITID>";
               
               xml_data+="</ROW>";
            }
         }
         catch(PersistanceException ex) {
             throw new ChangeUnitException(ex);
         }
         xml_data+="</BRANCH>";                  
         
       
        return xml_data;
    }
    
    public String getXmlBranch(String changeUnitId) throws ChangeUnitException {

       String xml_data="";
/*
	BRANCHNAME VARCHAR(100) not null primary key,
	CHANGEUNITID VARCHAR(100) not null,
	ORIGINCHANGEUNITID VARCHAR(100) not null
*/
         xml_data+="<BRANCH>";
         BranchDAO branchDAO = new BranchDAO();

         try{
            List<String> changeUnitIds = getAfterChangeUnitId(changeUnitId);
            
            for(String item :changeUnitIds){ 
            
                List<BranchDTO> list = branchDAO.findByChangeUnitId(item);

                for(BranchDTO dto : list){
                   xml_data+="<ROW>";

                   xml_data+="<BRANCHNAME>";
                   xml_data+=dto.getBranchName();
                   xml_data+="</BRANCHNAME>";
                   xml_data+="<CHANGEUNITID>";
                   xml_data+=dto.getChangeUnitId();
                   xml_data+="</CHANGEUNITID>";
                   xml_data+="<ORIGINCHANGEUNITID>";
                   xml_data+=dto.getOriginChangeUnitId();
                   xml_data+="</ORIGINCHANGEUNITID>";

                   xml_data+="</ROW>";
                }
            }
         }
         catch(PersistanceException ex) {
             throw new ChangeUnitException(ex);
         }
         xml_data+="</BRANCH>";                  
         
       
        return xml_data;
    }    
    
}
